<?php
namespace im\tables;

use MongoDB\BSON\ObjectID;
use MongoDB\BSON\Persistable;

class UserLink implements Persistable {
    
    private $id = null,
            $uid = 0,
            $link_map = [];
    
    public function __construct($from_uid,$to_uid,$info) {
        $this->id = new ObjectID();
        $this->uid = (int)$from_uid;
        $this->link_map[$to_uid] = (string)($info);
    }
            
    public function __get($name) {
        if(property_exists($this, $name)){
            return $this->$name;
        }
    }
    
    public function bsonSerialize()
    {
        return [
            '_id' => $this->id,
            'uid' => $this->uid,
            'link_map' => $this->link_map
        ];
    }
    
    public function bsonUnserialize(array $data)
    {
        $this->id = $data['_id'];
        $this->uid = $data['uid'];
        $this->link_map = $data['link_map'];
    }
}